<?php
/* @var $this GrainController */
/* @var $model Grain */
/* @var $form CActiveForm */
?>

<div class="form">

<?php 

if (!isset($modal)) {
        $form=$this->beginWidget('CActiveForm', array(
                'id'=>'grain-form',
                'htmlOptions'=>array('class'=>'form-horizontal'),
                'enableAjaxValidation'=>false,
        )); 
} else {
        $form=$this->beginWidget('CActiveForm', array(
                'id'=>'grain-form',
                'htmlOptions'=>array(
                        'class'=>'form-horizontal',
                        'onsubmit'=>"return false;",
                        'onkeypress'=>"if(event.keyCode == 13){ send(); }"
                ),
                'enableAjaxValidation'=>false,
        ));
}

?>

        <p class="note">Les champs marqués d'une <span class="required">*</span> sont requis.</p>

        <?php echo $form->errorSummary($model,NULL,NULL,array("class"=>"alert alert-danger")); ?>
        
        <?php if (isset($modal)) echo CHtml::hiddenField('modal',1); ?>
        <?php echo $form->hiddenField($model,'idseliste',array("value"=>Yii::app()->user->id)); ?>

        <?php
        if (Yii::app()->user->admin_grain && !isset($modal) && !$model->isNewRecord) {
        ?>
                <div class="form-group">
                        <?php echo CHtml::label("Ajouté par",'idseliste',array("class"=>"col-lg-2 control-label")); ?>
                        <div class="col-lg-10"><?php echo CHtml::textField('idseliste',$model->idseliste0->nom . " " . $model->idseliste0->prenom . " (" . $model->idseliste0->pseudo . ")",array("class"=>"form-control","disabled"=>"disabled")); ?></div>
                </div>
        <?php
        }
        ?>
        
        <?php
        if (isset($modal)) {
                echo $form->hiddenField($model,'idtype');
        } else {
        ?>
                <div class="form-group">
                        <?php echo $form->label($model,'idtype',array("class"=>"col-lg-2 control-label")); ?>
                        <div class="col-lg-10">
                                <?php 
                                $data = CHtml::listData(Type::model()->findAll(array('order'=>'lib asc')),
                                        'id', 
                                        'lib'
                                );
                                echo $form->dropDownList($model,'idtype',$data,array("class"=>"form-control"));
                                ?>
                        </div>
                </div>
        <?php
        }
        ?>
        
        <?php
        if (isset($modal)) {
                echo $form->hiddenField($model,'iddomaine');
        } else {
        ?>
                <div class="form-group">
                        <?php echo $form->label($model,'iddomaine',array("class"=>"col-lg-2 control-label")); ?>
                        <div class="col-lg-10">
                                <?php 
                                $data = CHtml::listData(Domaine::model()->findAll(array('order'=>'lib asc')),
                                        'id', 
                                        'lib'
                                );
                                echo $form->dropDownList($model,'iddomaine',$data,array("class"=>"form-control"));
                                ?>
                        </div>
                </div>
        <?php
        }
        ?>
        
        <div class="form-group<?php if ($model->getErrors('nom')) echo " has-error";?>">
                <?php echo $form->labelEx($model,'nom',array("class"=>"col-lg-2 control-label")); ?>
                <div class="col-lg-10"><?php echo $form->textField($model,'nom',array("class"=>"form-control","placeholder"=>"Saisir le nom du grain",'maxlength'=>255)); ?></div>
        </div>
        
        <div class="form-group<?php if ($model->getErrors('descr')) echo " has-error";?>">
                <?php echo $form->labelEx($model,'descr',array("class"=>"col-lg-2 control-label")); ?>
                <div class="col-lg-10"><?php echo $form->textArea($model,'descr',array("class"=>"form-control","placeholder"=>"Saisir la description du grain")); ?></div>
        </div>
        
        <div class="form-group<?php if ($model->getErrors('valeur')) echo " has-error";?>">
                <?php echo $form->labelEx($model,'valeur',array("class"=>"col-lg-2 control-label")); ?>
                <div class="col-lg-10"><?php echo $form->textField($model,'valeur',array("class"=>"form-control","placeholder"=>"Saisir la valeur du grain",'maxlength'=>255)); ?></div>
        </div>
        
        <div class="form-group<?php if ($model->getErrors('unite')) echo " has-error";?>">
                <?php echo $form->labelEx($model,'unite',array("class"=>"col-lg-2 control-label")); ?>
                <div class="col-lg-10"><?php echo $form->textField($model,'unite',array("class"=>"form-control","placeholder"=>"Saisir l'unité du grain",'maxlength'=>1)); ?></div>
        </div>
        
        <?php
        if (Yii::app()->user->admin_grain) {
        ?>
        <div class="form-group">
        	<?php echo $form->labelEx($model,'status',array("class"=>"col-lg-2 control-label")); ?>
			<div class="col-lg-10">
            	<?php 
                $data = array('1'=>"Validé","0"=>"En attente de validation");
                echo $form->dropDownList($model,'status',$data,array("class"=>"form-control"));
                ?>
            </div>
        </div>
        <?php 
		} else { 
			echo $form->hiddenField($model,'status',array("value"=>0)); 
		}
		?>
        
        <div class="form-group">
                <div class="col-lg-offset-2 col-lg-10">
                        <?php 
                        if (!isset($modal)) {
						?>
                                <?php echo CHtml::submitButton($model->isNewRecord ? 'Ajouter le grain' : 'Sauvegarder le grain',array("class"=>"btn btn-primary"));?> 
                                <?php echo CHtml::link($model->isNewRecord ? "Annuler l'ajout" : "Annuler les modifications",array('grain/admin'),array('class'=>"btn btn-sm btn-info"));?>
                        <?php
                        } else {
                                echo CHtml::Button('Ajouter le grain',array("class"=>"btn btn-primary sendgrain")); 
                        }
                        ?> 
                </div>
        </div>

<?php $this->endWidget(); ?>

</div><!-- form -->